package com.mask.im.business.controller.chat;

import com.mask.im.business.common.model.RestResponse;
import com.mask.im.business.service.IMCallService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @className： IMCallController
 * @Description: 通话管理类
 * @Author：jian
 * @Date：2025/10/11 08:48
 */
@Api("通话控制类")
@RestController
@RequestMapping("call")
public class IMCallController {
    @Resource
    private IMCallService callService;

    /**
     * 发起通话
     *
     * @param receiverId 接受者id
     * @param type       通话类型
     * @return
     */
    @ApiOperation("发起通话")
    @PostMapping("request")
    public RestResponse<?> requestCall(@RequestParam(name = "receiverId") Long receiverId, @RequestParam(name = "type") Integer type,@RequestBody String offer) {
        return callService.requestCall(receiverId, type,offer);
    }

    @ApiOperation("接听通话")
    @PostMapping("accept")
    public RestResponse<?> acceptCall(@RequestParam(name = "sendId") Long sendId,@RequestBody String answer) {
        return callService.acceptCall(sendId,answer);
    }

    @ApiOperation("取消通话")
    @PostMapping("cancel")
    public RestResponse<?> cancelCall(@RequestParam(name = "receiverId") Long receiverId) {
        return callService.cancelCall(receiverId);
    }

    @ApiOperation("拒绝通话")
    @PostMapping("reject")
    public RestResponse<?> rejectCall(@RequestParam(name = "sendId") Long sendId) {
        return callService.rejectCall(sendId);
    }


    @ApiOperation("结束通话")
    @PostMapping("end")
    public RestResponse<?> endCall(@RequestParam(name = "otherId") Long otherId){
        return callService.endCall(otherId);
    }


    @ApiOperation("同步candidate")
    @PostMapping("candidate")
    public RestResponse<?> candidate(@RequestParam(name = "otherId") Long otherId, @RequestBody String candidate){
        return callService.sendSignaling(otherId,candidate);
    }

    @ApiOperation("心跳")
    @PostMapping("/heartbeat")
    public RestResponse<?> heartbeat(@RequestParam Long otherId) {
        return callService.heartbeat(otherId);
    }

}
